<template>
	<view class="mainpadding">
		<u-popup :show="show" @close="close">
			<view class="mainpadding dingwei">
				<view class="textcenter sanshier xiaohei">选择提现位置</view>
				<view class="guanbi" @click="close">
					<u-icon name="close" size="19"></u-icon>
				</view>
				<view class="mainpadding ffffff margin_top">
					<view class="flexbetween xiahuaxian" @click="pay_type=2;show=false">
						<view class="flexleft ">
							<view class="margin_right1">
								<u-icon name="weixin-circle-fill" color="#28C445" size="34"></u-icon>
							</view>
							<view class="ershiba xiaohei">提现到储值</view>
						</view>
						<u-icon name="checkmark" color="#ED6D2D" v-if="pay_type==2" size="21"></u-icon>
					</view>
					<view class="flexbetween xiahuaxian margin_top"  @click="pay_type=1;show=false">
						<view class="flexleft ">
							<view class="margin_right1">
								<u-icon name="weixin-circle-fill" color="#28C445" size="34"></u-icon>
							</view>
							<view class="ershiba xiaohei">提现到微信</view>
						</view>
						<u-icon name="checkmark" color="#ED6D2D" v-if="pay_type==1"  size="21"></u-icon>
					</view>
				</view>
			</view>
		</u-popup>
		<view class="ershiba xiaohei">提现方式</view>
		<view class="flexbetween margin_top1" @click="txfs">
			<view class="flexleft">
				<view class="margin_right1">
					<u-icon name="weixin-circle-fill" color="#28C445" size="34"></u-icon>
				</view>
				<view class="">
					<view class="ershiba xiaohei">{{pay_type==1?"微信":"储值"}}</view>
					<view class="strongtext xiaohui ">立即到账</view>
				</view>
			</view>
			<u-icon name="arrow-right" color="#999999" v-if="listtype==1"></u-icon>
		</view>
		<view class="ffffff margin_top radius mainpadding">
			<view class="ershiba xiaohei">提现金额</view>
			<view class="flexleft margin_top">
				<view class="ershiba xiaohei">￥</view>
				<input type="digit" placeholder="请输入金额" step="0.1" v-model="pay_price">
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bighbtn" @click="submit">确定</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				pay_type:2,//1=微信,2=佣金提现
				pay_price:"",
				openid:"",
				listtype:1,//1佣金提现，2储值提现（只能提现到微信）
			}
		},
		onLoad(options) {
			if(options.type==2){
				this.pay_type = 1
			}
			this.listtype = options.type
			this.getopenid()
		},
		methods: {
			txfs(){
				if(this.listtype==1){
					this.show = true
				}
			},
			getopenid(){
				let _this = this
				uni.login({
					success(res) {
						if (res.code) {
							httpRequest.request('/api/user/getopenid', 'GET', {
								code:res.code
							}).then(resp => {
								_this.openid = resp.data.openid
							}).catch(err=>{
							})
						}
					}
				})
			},
			submit(){
				uni.showLoading({
					title:"请稍后",
					mask:true,
				})
				if(this.pay_price==""){
					httpRequest.toast("请输入金额")
					return false
				}
				let data = {
					price:this.pay_price,
					type:this.pay_type,
					openid:this.openid,
					datatype:this.listtype
				}
				httpRequest.request('/api/user/addWithdrawal', 'GET', data).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(() => {
							uni.navigateBack({
								delta:1
							})
						}, 1000)
					}
					
				})
			},
			close() {
				this.show = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
.guanbi{
	position: absolute;
	top: 30rpx;
	right: 30rpx;
}
</style>